/**
*	首页主JS
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-17
*/

function initbody(){
	var key   = 'apptheme';
	var ys 	  = js.request(key);
	maincolor = '#36648B';
	if(ys)js.setoption(key,ys);
	if(!ys)ys = js.getoption(key);
	if(ys)maincolor='#'+ys+'';
	
	adminname = '';
	adminface = '';
	xcy.init();
}
var xcy = {
	otherheight:0,
	initApp:function(){},
	resieze:function(){},
	pageParams:{},
	init:function(){
		this.resiezem();
		this.showtheme(maincolor);
		$(window).resize(xcy.resiezem);
		adminname 	= js.getoption('adminname');
		adminface 	= js.getoption('adminface');
		usertype 	= parseFloat(js.getoption('usertype','0'));
		systemtitle = js.getoption('systemtitle', systemtitle);
		importcss('main');
	
		var da={nlogin:false},cans={};
		var bstr= js.request('bstr'),key = js.request('key');
		if(key)bstr = sessionStorage.getItem(key);
		if(bstr){
			da = JSON.parse(jm.base64decode(bstr));
			this.pageParams = da;
		}
		if(!da.url){
			bstr = js.getoption('defnowurl');
			if(bstr){
				da = JSON.parse(bstr);
				this.pageParams = da;
			}
		}
		if(!this.islogin() && !da.nlogin){
			var wlg = 'login';
			if(js.web.ismobile())wlg='loginwe';
			this.addtabs('登录','login/'+wlg+'');
			return;
		}
		var na = da.name,url = da.url;
		if(da.params)cans = da.params;
		if(!url){
			url='home';
			cans.title = systemtitle;
			cans.cnum = '';
		}
		if(cans.cnum){
			var ico = js.getoption('ico_'+cans.cnum+'');
			if(ico)get('iconindex').href = ico;
		}
		this.addtabs(na,url, cans);
	},
	showtheme:function(lx){
		var str = '--main-color:'+lx+';';
		if(js.web.ismobile())str+='--font-size:18px;';
		$('#autostyle').remove();
		$('body').append('<style id="autostyle">body{'+str+'}</style>');
	},
	islogin:function(){
		token = js.getoption('token');
		return (token);
	},
	getheight:function(ss){
		if(!ss)ss=0;
		var hei = this.otherheight;
		if(get('header') && get('header').style.display!='none')hei+=50;
		var dx = winHb()-hei+ss;
		return dx;
	},
	setTitle:function(na){
		$('#header_title').html(na);
		document.title = na;
	},
	resiezem:function(){
		var hei = xcy.getheight();
		if(!this.bodyflowbo)$('#mainbody').css('height',''+hei+'px');
		viewheight = hei;
		viewwidth  = winWb();
		if(xcy.touchobj)xcy.touchobj.resize();
		xcy.resieze();
		var obj = $('div[resizes]'),i,o1,vhi;
		for(i=0;i<obj.length;i++){
			o1 = $(obj[i]);
			vhi= parseFloat(o1.attr('resizes'));
			o1.css('height',''+(viewheight-vhi)+'px');
		}
	},
	bodyflow:function(bt){
		document.body.style.overflow = 'auto';
		if(!bt)document.body.style.background = 'white';
		var o1t = get('mainbody').style;
		o1t.overflow   = 'auto';
		if(!bt)o1t.background = 'white';
		o1t.height     = 'auto';
		this.bodyflowbo = true;
	},
	addtabs:function(na,url,cans){
		if(!cans)cans={};
		if(!na)na= systemtitle;
		this.setTitle(na);
		this.addcont(url, 'mainbody', cans);
	},
	addtabsok:function(da, rand, urlpms,view){
		var s = da;
			s = s.replace(/\{rand\}/gi, rand);
			s = s.replace(/\{params\}/gi, "var params="+urlpms+";");
		$('#'+view+'').html(s);
		this.resiezem();
	},
	addcont:function(url,view,params,sfun){
		var rand   = js.getrand();
		if(!params)params={};
		var urlpms = JSON.stringify(params);
		if(url.indexOf('.html')==-1)url+='.html';
		var cans = {
			'type':'get',
			'url':'list/'+url+'?'+rand+'',
			'success':function(da){
				if(!da)da='无法加载：'+url+'';
				xcy.addtabsok(da, rand, urlpms, view);
				if(sfun)sfun();
			},
			'error':function(e){
				xcy.addtabsok(''+cans.url+'('+e.status+')'+e.statusText+';', rand, urlpms, view);
			}
		}
		$.ajax(cans);
	},
	opennei:function(cans, bo){
		var url = 'index.html?bstr='+jm.base64encode(JSON.stringify(cans))+'';if(bo)return url;
		window.open(url);
	},
	openkey:function(cans){
		var url = this.openurl(cans);
		window.open(url);
	},
	openurl:function(cans){
		var str = jm.base64encode(JSON.stringify(cans));
		var key = md5(str);
		sessionStorage.setItem(key, str);
		var url = 'index.html?key='+key+'';
		return url;
	},
	openinput:function(cans, da){
		importjs('input', function(){
			js.input.open(cans, da);
		});
	},
	openxiang:function(cans, da){
		importjs('xiang', function(){
			js.xiang.open(cans, da);
		});
	},
	setheight:function(id,hei){
		var obj = $('#'+id+'');
		hei = hei - obj.offset().top;
		obj.css('height',''+hei+'px');
	},
	opencompany:function(d,isn,isx){
		var url='home';
		if(d.hmode=='1')url='company/homeim';
		var cans = {url:url,name:d.name,params:{cnum:d.num,title:d.name}}
		if(isx){js.setoption('defnowurl', cans);return;}
		if(isn){
			this.openkey(cans);
		}else{
			js.location(this.openurl(cans));
		}
	},
	getacturl:function(bh,act){
		return 'api/flow/action?num='+bh+'&act='+act+'';
	}
}
function addtabs(cans){
	if(window.home && !js.web.ismobile()){
		home.addtabs(cans);
	}else{
		xcy.openkey(cans);
	}
}